<?php
/*
PluginName:最新日志
PluginUrl:http://www.lisijie.org
PluginAuthor:lisijie
PluginAuthorUrl:http://www.lisijie.org
PluginDesc:最新日志widget for Jblog2
PluginVer:2.0.0
*/

class RecentblogWidget extends Widget {
	
	function RecentblogWidget() {
		$this->Widget(array('title'=>'最新日志'));
	}
	
	function display() {
		if ( !($data = $this->cache->get('widget_recentblog')) ) {
			$data = "<ul>\n";
			$query = $this->db->query("SELECT id,title,alias,dateline,username,views,comments FROM ".tname('post')." 
			WHERE `type` = 'blog' AND `status` = 1 ORDER BY dateline DESC LIMIT 10");
			while ( $row = $this->db->fetch_array($query) ) {
				$data .= '<li><a href="'.url("mod=post&id={$row[id]}&alias={$row[alias]}").'">'.cut_str($row['title'],30).'</a></li>'."\n";
			}
			$data .= "</ul>\n";
			$this->cache->set('recentblog', $data);
		}
		return $data;		
	}
	
	function recache() {
		$GLOBALS['cache']->del('widget_recentblog');	
	}
}
add_action('blog_submit', array('RecentblogWidget','recache'));
?>